gh-153782: Make traceback.print_list() delegate to format_list()#153783
gh-153782: Make traceback.print_list() delegate to format_list()#153783basil wants to merge 1 commit into
Conversation
print_list() and format_list() each formatted a StackSummary with the same expression, so their outputs agreed only by duplication. Route print_list() through format_list() so print_list(x), keeping the two public helpers from drifting, and add a regression test that print_list() matches format_list() for tuple, FrameSummary, and StackSummary inputs.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
Per my comment from the PR description:
I will wait for a maintainer to apply the |
|
I do not think it is really worth it. The current code is working and such change would create a drift in backports. We do not accept such changes in general. I think it is fine as is. |
|
However the tests, if not already there, are worth it. |
|
If tests do not yet exist, we can accept such changes. Can you confirm that? |
|
I think the current code is OK. I understand your reasoning. However, these functions are essentially kept together and they are simple functions. They have not drifted for 11 years. Test coverage would be cool to have, yes. |
|
Thank you, that makes sense. This PR adds |
Fixes #153782
In
Lib/traceback.py, the public helpersprint_list()andformat_list()independently contain the same formatting expression, so their outputs agree only by duplication. This PR routesprint_list()throughformat_list()so that they share a single formatting path, with no change in behavior.Problem
format_list()returns the formatted lines:print_list()writes those same lines, but re-derives them with the identical expression instead of reusingformat_list():The outputs match only because
StackSummary.from_list(extracted_list).format()is duplicated in both. Any future change to how a frame list is formatted has to be applied in both places to prevent the two public helpers from silently diverging.Solution
Have
print_list()iterateformat_list():This eliminates the possibility of drift and mirrors the delegation already used in this module; for example,
print_tb()callsprint_list()rather than re-derivingextract_tb(...).format().Testing Done
format_list()is exactly the same expression, so output is identical for every documented input type. Therefore, there is no change in behavior. This PR adds a regression test asserting this equality for tuple,FrameSummary, andStackSummaryinputs.Documentation
I have not proposed an entry in
Misc/NEWS.d, as the developer guide says that strictly internal changes with no user-visible effect do not require one. I am happy to add one if a maintainer prefers.traceback.print_list()delegate toformat_list()#153782